package com.hkts.naturalgas.performance.controller;


import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hkts.naturalgas.performance.entity.HkActType;
import com.hkts.naturalgas.performance.service.IHkActTypeService;
import com.hkts.naturalgas.utils.CustomPageUtils;
import com.hkts.naturalgas.utils.Result;
import com.hkts.naturalgas.utils.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author yck
 * @since 2022-09-02
 */
@RestController
@RequestMapping("/performance/hkActType")
public class HkActTypeController {
    private final Logger logger = LoggerFactory.getLogger(HkActTypeController.class);

    @Autowired
    public IHkActTypeService iHkActTypeService;

    /**
     * 分页查询数据
     *
     * @param page      分页信息
     * @param hkActType 查询条件
     * @return
     */
    @ResponseBody
    @GetMapping("/getHkActTypePageList")
    public Result<Object> getHkActTypePageList(Page<HkActType> page, HkActType hkActType) {
        return ResultUtil.data(CustomPageUtils.getCustomPage(iHkActTypeService.selectPage(page, hkActType)));
    }

    /**
     * 保存和修改公用的
     *
     * @param hkActType 传递的实体
     * @return saveOrUpdate
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hkActTypeSave")
    public Result<Object> hkActTypeSave(HkActType hkActType) {
        iHkActTypeService.saveOrUpdate(hkActType);
        return ResultUtil.success("保存成功");
    }

    /**
     * 根据id获取对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/hkActTypeGetById")
    public Result<Object> hkActTypeGetById(String id) {
        HkActType byId = iHkActTypeService.getById(id);
        return ResultUtil.data(byId);
    }

    /**
     * 根据id删除对象
     *
     * @param id 实体ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hkActTypeDelete")
    public Result<Object> hontUserDelete(String id) {
        iHkActTypeService.removeById(id);
        return ResultUtil.success("删除成功");
    }

    /**
     * 批量删除对象
     *
     * @param item 实体集合ID
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.POST, value = "/hkActTypeBatchDelete")
    public Result<Object> deleteBatchIds(String item) {
        List<String> ids = (List<String>) JSON.parse(item);
        iHkActTypeService.removeByIds(ids);
        return ResultUtil.success("删除成功");
    }

    /**
     * 获取所有活动类型
     * @return 0 失败  1 成功
     */
    @ResponseBody
    @RequestMapping(method = RequestMethod.GET, value = "/getAllActType")
    public Result<Object> getAllActType() {
        HkActType byId = new HkActType();
        List<HkActType> hkActTypes = iHkActTypeService.selectList(byId);
        return ResultUtil.data(hkActTypes);
    }

}
